#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main() {
    int year = 0;
    int month = 0;
    while (~scanf("%d %d", &year, &month))
    {
        int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
        if ((year % 100 != 0) && (year % 4 == 0) || (year % 400 == 0))
        {
            arr[2] = 29;
        }
        printf("%d\n", arr[month]);
    }
    return 0;
}